home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 9 / The PC-SIG Library on CD ROM - Ninth Edition.iso / 001_100 / DISK0041 / DISK0041.ZIP / MSCOMM.ASM < prev    next >
Assembly Source File  |  1984-12-08  |  19KB  |  623 lines

  1.     public    data, spack, rpack, rpack5, portval, port1, port2, hierr
  2.     public    prtbase, nports, port3, port4
  3.     include msdefs.h
  4.  
  5. gettim    equ    2CH        ; Get the time of day. 
  6. maxlp    equ    100        ; Use as number of times to loop (in inchr).
  7. true    equ    1
  8. false    equ    0
  9. mntrgl    equ    bufsiz/4    ; Low point = 1/4 of the way full.
  10. maxpack    equ    78H        ; largest packet we can handle
  11.  
  12. datas    segment    public 'datas'
  13.     extrn    flags:byte, trans:byte, pack:byte, count:word, xofsnt:byte
  14.  
  15. prtbase    label    byte
  16. port1    prtinfo    <0FFFH,0,defpar,1,0,defhand,floxon>
  17. port2    prtinfo    <0FFFH,0,defpar,1,0,defhand,floxon>
  18. port3     prtinfo    <0FFFH,0,defpar,1,0,defhand,floxon>
  19. port4    prtinfo    <0FFFH,0,defpar,1,0,defhand,floxon>
  20.     rept    portmax-4
  21.     prtinfo    <0FFFH,0,defpar,1,0,defhand,floxon>
  22.     endm
  23.  
  24. ;; systems with two ports can set portval to port1 or port2.
  25. ;; systems with more than two ports can set nports higher,
  26. ;; then set portval to the address prtbase+(#-1)*size prtinfo
  27. ;; where # is the desired port.
  28.  
  29. portval    dw    port1        ; Default is to use port 1.
  30. nports    db    2        ; # of known ports
  31. hierr    db    0        ; Non-ascii char (non-zero if yes).
  32. spmes    db    'Spack:  $'
  33. rpmes     db    'Rpack:  $'
  34. crlf    db      cr,lf,'$'
  35. infms0  db    'Waiting .....$'
  36. hibit    db    'Warning - Non Ascii char$'
  37. cemsg    db    'User intervention$'
  38. temp    dw    0
  39. tmp    db    ?,'$'
  40. prvtyp  db      0               ; Type of last packet sent. [27e]
  41. pktptr  dw    ?        ; Position in receive packet.
  42. incnt    dw    ?        ; Number of chars read in from port.
  43. loopct    db    ?        ; Loop counter.
  44. time     dw    ?        ; When we should timeout. 
  45.     dw    ?        ; Want a double word.
  46. packet  db    ?,?,?,?        ; Packet (data is part of it).
  47. data    db    5AH DUP(?)    ; Data and checksum field of packet.
  48. recpkt  db    maxpack DUP(?)    ; Receive packet storage (use the following).
  49.         db      ?,?,?,?         ; Space for '$' and other stuff.  
  50. crctab    dw    00000H
  51.     dw    01081H
  52.     dw    02102H
  53.     dw    03183H
  54.     dw    04204H
  55.     dw    05285H
  56.     dw    06306H
  57.     dw    07387H
  58.     dw    08408H
  59.     dw    09489H
  60.     dw    0A50AH
  61.     dw    0B58BH
  62.     dw    0C60CH
  63.     dw    0D68DH
  64.     dw    0E70EH
  65.     dw    0F78FH
  66.  
  67. crctb2    dw    00000H
  68.     dw    01189H
  69.     dw    02312H
  70.     dw    0329BH
  71.     dw    04624H
  72.     dw    057ADH
  73.     dw    06536H
  74.     dw    074BFH
  75.     dw    08C48H
  76.     dw    09DC1H
  77.     dw    0AF5AH
  78.     dw    0BED3H
  79.     dw    0CA6CH
  80.     dw    0DBE5H
  81.     dw    0E97EH
  82.     dw    0F8F7H
  83. datas    ends
  84.  
  85. code    segment    public
  86.     extrn    prtchr:near, clrbuf:near, outchr:near
  87.     extrn    sppos:near, stpos:near, biterr:near, intmsg:near
  88.     extrn    clearl:near, rppos:near, errpack:near
  89.     assume     cs:code, ds:datas
  90.  
  91. ;    Packet routines
  92.  
  93. ; Send_Packet
  94. ; This routine assembles a packet from the arguments given and sends it
  95. ; to the host.
  96. ;
  97. ; Expects the following:
  98. ;    AH     - Type of packet (D,Y,N,S,R,E,F,Z,T)
  99. ;    ARGBLK - Packet sequence number
  100. ;    ARGBK1 - Number of data characters
  101. ; Returns: +1 always
  102.  
  103. SPKT    PROC    NEAR
  104.  
  105. spack:     push ax            ; Save the packet type.
  106.         mov prvtyp,ah           ; Remember packet type. [27e]
  107.     call clrbuf        ; Clear the input buffer. [20e]
  108.     mov bx,offset packet    ; Get address of the send packet.
  109.     mov ah,trans.ssoh    ; Get the start of header char.
  110.     mov [bx],ah        ; Put in the packet.
  111.     inc bx            ; Point to next char.
  112.     mov ax,pack.argbk1    ; Get the number of data chars.
  113.     xchg ah,al
  114.     mov al,trans.chklen    ; Length of checksum.
  115.     dec al            ; Extra length of checksum.
  116.     add ah,' '+3        ; Real packet character count made printable.
  117.     add ah,al        ; Account for checksum length in count.
  118.     mov [bx],ah        ; Put in the packet.
  119.     inc bx            ; Point to next char.
  120.     mov ch,0        ; For the 16 bit checksum.
  121.     mov cl,ah        ; Start the checksum.
  122.     mov ax,pack.argblk    ; Get the packet number.
  123.     add al,' '        ; Add a space so the number is printable.
  124.     mov [bx],al        ; Put in the packet.
  125.     inc bx            ; Point to next char.
  126.     add cx,ax        ; Add the packet number to the checksum.
  127.     pop ax            ; Get the packet type.
  128.     mov [bx],ah        ; Put in the packet.
  129.     inc bx            ; Point to next char.
  130.     mov al,0
  131.     xchg ah,al
  132.     add cx,ax        ; Add the type to the checksum.
  133.     mov dx,pack.argbk1    ; Get the packet size.
  134. spack2: cmp dx,0        ; Are there any chars of data?
  135.      jz spack3        ;  No, finish up.
  136.     dec dx            ; Decrement the char count.
  137.     mov al,[bx]        ; Get the next char.
  138.     inc bx            ; Point to next char.
  139.     mov ah,0
  140.     add cx,ax        ; Add the char to the checksum.
  141.     cmp al,0
  142.     jns spack2
  143.     cmp hierr,0ffH        ; Printed message already?
  144.     je spack2        ; Yes, then that's it.
  145.     push bx
  146.     push cx
  147.     push dx
  148.     call biterr
  149.     pop dx
  150.     pop cx
  151.     pop bx
  152.     mov hierr,0FFH        ; set err flag. 
  153.     jmp spack2        ; Go try again.
  154. spack3:    cmp trans.chklen,2    ; What kind of checksum are we using.
  155.     je spackx        ; 2 characters.
  156.     jg spacky        ; 3 characters.
  157.     mov ah,cl        ; 1 char: get the character total.
  158.     mov ch,cl        ; Save here too (need 'cl' for shift).
  159.     and ah,0C0H        ; Turn off all but the two high order bits.
  160.     mov cl,6
  161.     shr ah,cl        ; Shift them into the low order position.
  162.     mov cl,ch
  163.     add ah,cl        ; Add it to the old bits.
  164.     and ah,3FH        ; Turn off the two high order bits.  (MOD 64)
  165.     add ah,' '        ; Add a space so the number is printable.
  166.     mov [bx],ah        ; Put in the packet.
  167.     inc bx            ; Point to next char.
  168.     jmp spackz        ; Add EOL char.
  169. spacky:    mov al,0        ; Get a null.
  170.     mov [bx],al        ; To determine end of buffer.
  171.     push bx            ; Don't lose our place.
  172.     mov bx,offset packet+1    ; First checksummed character.
  173.     call crcclc        ; Calculate the CRC.
  174.     pop bx
  175.     push cx
  176.     mov ax,cx        ; Manipulate it here.
  177.     and ax,0F000H        ; Get 4 highest bits.
  178.     mov cl,4
  179.     shr ah,cl        ; Shift them over 4 bits.
  180.     add ah,' '        ; Make printable.
  181.     mov [bx],ah        ; Add to buffer.
  182.     inc bx
  183.     pop cx            ; Get back checksum value.
  184. spackx:    push cx            ; Save it for now.
  185.     and cx,0FC0H        ; Get bits 6-11.
  186.     mov ax,cx
  187.     mov cl,6
  188.     shr ax,cl        ; Shift them bits over.
  189.     add al,' '        ; Make printable.
  190.     mov [bx],al        ; Add to buffer.
  191.     inc bx
  192.     pop cx            ; Get back the original.
  193.     and cx,003FH        ; Get bits 0-5.
  194.     add cl,' '        ; Make printable.
  195.     mov [bx],cl        ; Add to buffer.
  196.     inc bx
  197. spackz:    mov ah,trans.seol    ; Get the EOL the other host wants.
  198.     mov [bx],ah        ; Put in the packet.
  199.     inc bx            ; Point to next char.
  200.     mov ah,0        ; Get a null.
  201.     mov [bx],ah        ; Put in the packet.
  202.     cmp flags.debug,0    ; debug mode.
  203.     je spack4
  204.     inc bx
  205.     mov ah,'$'
  206.     mov [bx],ah
  207.     call sppos
  208.     call clearl        ; Clear to end of line.
  209.     mov dx,offset crlf
  210.     mov ah,prstr
  211.     int dos
  212.     call clearl        ; Next line too.
  213.     call sppos        ; Reposition cursor.
  214.     mov ah,prstr
  215.     mov dx,offset spmes
  216.     int dos
  217.     mov dx,offset packet
  218.     mov ah,prstr
  219.     int dos            ; debug end.
  220. spack4: call outpkt        ; Call the system dependent routine.
  221.      jmp r
  222.     jmp rskp
  223. SPKT    ENDP 
  224.  
  225. ;    Write out a packet.
  226.  
  227. OUTPKT  PROC    NEAR
  228.     mov dh,trans.spad    ; Get the number of padding chars.
  229. outpk2: dec dh
  230.     cmp dh,0
  231.     jl outpk3        ; If none left proceed.
  232.     mov ah,trans.spadch    ; Get the padding char.
  233.     call outchr        ; Output it.
  234.      jmp r            ; Say we failed. [25]
  235.     jmp outpk2
  236. outpk3: mov bx,offset packet    ; Point to the packet.
  237. outlup: mov ah,[bx]        ; Get the next character.
  238.     cmp ah,0        ; Is it a null?
  239.     jnz outlp2
  240.     jmp rskp
  241. outlp2: call outchr        ; Output the character.
  242.      jmp r
  243.     inc bx            ; Increment the char pointer.
  244.     jmp outlup
  245. OUTPKT  ENDP
  246.  
  247. ; Calculate the CRC.  Returns the CRC in CX.  Destroys: BX, AX.
  248. crcclc:    push dx
  249.     push si
  250.     mov dx,0        ; Initial CRC value is 0.
  251. crc0:    mov al,[bx]        ; Get the first char of the string.
  252.     cmp al,0        ; If null, then we're done.
  253.     je crc1
  254.     inc bx
  255.     xor al,dl        ; Xor input with lo order byte of CRC.
  256.     mov ah,al        ; Get a copy.
  257.     and ah,0F0H        ; Get hi 4 bits.
  258.     mov cl,4
  259.     shr ah,cl        ; Right justify.
  260.     and al,0FH        ; Get lo 4 bits.
  261.     push bx
  262.     mov si,offset crctb2    ; Low portion of CRC factor.
  263.     mov bh,0
  264.     mov bl,al
  265.     add bl,al        ; Get word index.
  266.     mov cx,[si+bx]        ; Low portion.
  267.     mov si,offset crctab    ; High portion of CRC factor.
  268.     mov bh,0
  269.     mov bl,ah
  270.     add bl,ah        ; Get word index.
  271.     mov bx,[si+bx]
  272.     xor bx,cx        ; Add the two.
  273.     mov cl,8
  274.     shr dx,cl        ; Shift CRC 8 bits to the right.
  275.     xor dx,bx        ; XOR table value and CRC.
  276.     pop bx            ; Retrieve index.
  277.     jmp crc0
  278. crc1:    mov cx,dx        ; Return it in CX.
  279.     pop si
  280.     pop dx
  281.     ret
  282.  
  283. ; Receive_Packet
  284. ; This routine waits for a packet arrive from the host.  It reads
  285. ; chars until it finds a SOH.
  286.  
  287. RPACK    PROC    NEAR
  288. rpack5: call inpkt        ; Read up to a carriage return.
  289.      jmp r            ;  Return bad.
  290. rpack0: call getchr        ; Get a character.
  291.      jmp r            ;  Hit the carriage return, return bad.
  292.     cmp al,trans.rsoh    ; Is the char the start of header char?
  293.      jne rpack0        ;  No, go until it is.
  294. rpack1: call getchr        ; Get a character.
  295.      jmp r            ;  Hit the carriage return, return bad.
  296.     cmp al,trans.rsoh    ; Is the char the start of header char?
  297.      jz rpack1        ;  Yes, then go start over.
  298.     mov ch,0        ; For 16-bit checksum.
  299.     mov cl,al        ; Start the checksum.
  300.     mov ah,0
  301.     mov pack.argbk1,ax    ; Save the data count.
  302.     call getchr        ; Get a character.
  303.      jmp r            ;  Hit the carriage return, return bad.
  304.     cmp al,trans.rsoh    ; Is the char the start of header char?
  305.      jz rpack1        ;  Yes, then go start over.
  306.     mov ah,0
  307.     add cx,ax        ; Add it to the checksum.
  308.     sub al,' '        ; Get the real packet number.
  309.     mov ah,0
  310.     mov pack.argblk,ax    ; Save the packet number.
  311.     call getchr        ; Get a character.
  312.      jmp r            ;  Hit the carriage return, return bad.
  313.     cmp al,trans.rsoh    ; Is the char the start of header char?
  314.      jz rpack1        ;  Yes, then go start over.
  315.     mov ah,0
  316.     mov temp,ax        ; Save the message type. [11]
  317.         mov bp,portval          ; Point to current port structure. [27e]
  318.         cmp ds:[bp].ecoflg,0    ; Is the host echoing? [27e]
  319.         jne rpak11              ; No, packets not echoed. [27e]
  320.         cmp al,prvtyp           ; Packet type same as last sent? [27e]
  321.         je rpack5               ; Yes, chuck echoed packet. [27e]
  322. rpak11:    add cx,ax        ; Add it to the checksum.
  323. ; Start of change.
  324. ; Now determine block check type for this packet.  Here we violate the layered
  325. ; nature of the protocol by inspecting the packet type in order to detect when
  326. ; the two sides get out of sync.  Two heuristics allow us to resync here:
  327. ;   a. An S packet always has a type 1 checksum.
  328. ;   b. A NAK never contains data, so its block check type is LEN-2. 
  329.     push cx
  330.     mov cl,al
  331.     mov ax,pack.argbk1    ; Get back the size.
  332.     sub al,34        ; unchar(len) - 2, for SEQ & TYPE fields.
  333.     mov ah,trans.chklen    ; Checksum length we expect.
  334.     cmp cl,'S'        ; Is this an "S" packet?
  335.     jne rpk0        ; Nope.
  336.     mov ah,1        ; Yes, use 1 char checksum.
  337. rpk0:    cmp cl,'N'        ; Is this a NAK?
  338.     jne rpk1        ; Nope.
  339.     mov ah,al        ; So, len - 2 is checksum type.
  340. rpk1:    mov trans.chklen,ah    ; Then, this is the chksum length.
  341.     sub al,ah        ; Real size of data.
  342.     mov dh,al        ; Need it here.
  343.     mov ah,0
  344.     mov pack.argbk1,ax    ; And here.
  345.     pop cx    
  346. ; End of change.
  347.     mov bx,offset data    ; Point to the data buffer.
  348. rpack2: dec dh            ; Any data characters?
  349.      js rpack3        ;  If not go get the checksum.
  350.     call getchr        ; Get a character.
  351.      jmp r            ;  Hit the carriage return, return bad.
  352.     cmp al,trans.rsoh    ; Is the char the start of header char?
  353.      jnz rpak2a
  354.     jmp rpack1        ;  Yes, then go start over.
  355. rpak2a:    mov [bx],al        ; Put the char into the packet.
  356.     inc bx            ; Point to the next character.
  357.     mov ah,0
  358.     add cx,ax        ; Add it to the checksum.
  359.     jmp rpack2        ; Go get another.
  360. rpack3: call getchr        ; Get a character.
  361.      jmp r            ;  Hit the carriage return, return bad.
  362.     cmp al,trans.rsoh    ; Is the char the start of header char?
  363.      jnz rpk3x
  364.      jmp rpack1        ;  Yes, then go start over.
  365. rpk3x:    sub al,' '        ; Turn the char back into a number.
  366.     cmp trans.chklen,2    ; What checksum length is in use.
  367.     je rpackx        ; Two character checksum.
  368.     jg rpacky        ; Three character CRC.
  369.     mov dh,cl        ; 1 char - get the character total.
  370.     and dh,0C0H        ; Turn off all but the two high order bits.
  371.     mov ch,cl
  372.     mov cl,6
  373.     shr dh,cl        ; Shift them into the low order position.
  374.     mov cl,ch
  375.     add dh,cl        ; Add it to the old bits.
  376.     and dh,3FH        ; Turn off the two high order bits.  (MOD 64)
  377.     cmp dh,al        ; Are they equal?
  378.      jz rpack4        ; If so finish up.
  379.     jmp rpack6        ; No, we fail.
  380. rpacky:    mov tmp,al        ; Save value from packet here.
  381.     mov ah,0        ; Three character CRC.
  382.     push bx
  383.     mov bx,pktptr        ; Where we are in the packet.
  384.     dec bx
  385.     mov [bx],ah        ; Add null to signify end of buffer.
  386.     mov bx,offset recpkt+1    ; Where data for CRC is.
  387.     call crcclc        ; Calculate the CRC and put into CX.
  388.     pop bx
  389.     push cx
  390.     mov ax,cx        ; Manipulate it here.
  391.     and ax,0F000H        ; Get 4 highest bits.
  392.     mov cl,4
  393.     shr ah,cl        ; Shift them over 4 bits.
  394.     pop cx            ; Get back checksum value.
  395.     cmp ah,tmp        ; Is what we got == what we calculated?
  396.     jne rpack6
  397.     call getchr        ; Get next character of checsum.
  398.      jmp r            ; Failed.    
  399.     cmp al,trans.rsoh    ; Restarting?
  400.      jz rpack7
  401.     sub al,' '        ; Get back real value.
  402. rpackx:    mov tmp,al        ; Save here for now.
  403.     push cx            ; Two character checksum.
  404.     and cx,0FC0H        ; Get bits 6-11.
  405.     mov ax,cx
  406.     mov cl,6
  407.     shr ax,cl        ; Shift them bits over.
  408.     pop cx            ; Get back the original.
  409.     cmp al,tmp        ; Are they equal?
  410.      jne rpack6        ; No, we fail.
  411.     call getchr        ; Get last character of checsum.
  412.      jmp r            ; Failed.    
  413.     cmp al,trans.rsoh    ; Restarting?
  414.      jz rpack7
  415.     sub al,' '        ; Get back real value.    
  416.     and cx,003FH        ; Get bits 0-5.
  417.     cmp al,cl        ; Do the last chars match?
  418.     jne rpack6
  419. rpack4: mov ah,0
  420.     mov [bx],ah        ; Put a null at the end of the data.
  421.     mov ax,temp        ; Get the type.   [11]
  422.     xchg al,ah        ; Packet type should be in AH.
  423.     jmp rskp
  424. rpack6:    ret
  425. rpack7:    jmp rpack1        ; For the jump out of range.
  426. RPACK    ENDP
  427.  
  428.  
  429. INPKT    PROC    NEAR
  430.     mov bl,flags.cxzflg    ; Remember original value. [20b]
  431.     mov tmp,bl        ; Store it here. [20b]
  432. inpkt0:    call inchr        ; Get a character. [27a]
  433.      jmp inpkt8        ;  Return failure. [27a]
  434.      nop            ;  Make it three bytes long. [27a]
  435.     cmp ah,trans.rsoh    ; Is it SOH char? [27a]
  436.     jne inpkt0        ; No hold out for SOH. [27a]
  437. inpkt1:    mov bx,offset recpkt    ; Point to the beginning of the packet.
  438.     mov incnt,0
  439.     mov [bx],ah        ; Add SOH to buffer. [27a]
  440.     inc bx            ; Increment pointer. [27a]
  441.     inc incnt        ; Increment counter. [27a]
  442. inpkt2:    call inchr        ; Get a character.
  443.      jmp inpkt8        ;  Return failure. [20b]
  444.      nop            ;  Make it three bytes long. [20b] 
  445.     cmp ah,trans.rsoh    ; Starting over again? [27a]
  446.     je inpkt1
  447.     mov [bx],ah        ; Put the char in the packet.
  448.     inc bx
  449.     inc incnt
  450.     cmp ah,trans.reol    ; Is it the EOL char?
  451.     je inpkt3        ; ended by eol, keep going
  452.     cmp incnt,maxpack    ; is it too big?
  453.     jbe inpkt2        ; no, keep going
  454.     jmp inpkt1        ; else just start over
  455. inpkt3:    cmp incnt,1        ; Ignore bare CR.   [2 start]
  456.     je inpkt1
  457.     mov bp,portval
  458.     cmp ds:[bp].hndflg,0    ; Waiting for handshake?
  459.     jz inpkt5        ; If not then proceed.
  460. inpkt4: call inchr        ; Wait for the turn around char.
  461.      jmp inpkt8        ;  Return failure. [20b]
  462.      nop            ;  Make it three bytes long.  [20b]
  463.     cmp ah,trans.rsoh    ; Start of packet? [27a]
  464.     je inpkt1        ; Yes go start over. [27a]
  465.     mov bp,portval
  466.     cmp ah,ds:[bp].hands    ; Is it the IBM turn around character?
  467.     jne inpkt4        ; If not, go until it is.
  468. inpkt5:    cmp flags.debug,0    ; In debug mode?
  469.     je inpkt6
  470.     mov ah,'$'
  471.     mov [bx],ah
  472.     call rppos
  473.     call clearl        ; Clear to end of line.
  474.     mov dx,offset crlf
  475.     mov ah,prstr
  476.     int dos
  477.     call clearl        ; Next line too.
  478.     call rppos        ; Reposition cursor.
  479.     mov ah,prstr
  480.     mov dx,offset rpmes
  481.     int dos
  482.     mov dx,offset recpkt
  483.     mov ah,prstr
  484.     int dos            ; debug end.
  485. inpkt6:    mov bx,offset recpkt
  486.     mov pktptr,bx        ; Save the packet pointer.
  487.     mov bl,tmp        ; Get the original value. [20b]
  488.     cmp bl,flags.cxzflg    ; Did ^X/^Z flag change? [20b]
  489.     je inpkt7        ; If not, just return.  [20b]
  490.     cmp flags.cxzflg,'E'    ; Error packet?
  491.     je inpkt9
  492.     call intmsg         ; Else, say we saw the interrupt. [20b]
  493. inpkt7: jmp rskp        ; If so we are done.
  494. inpkt8:    cmp flags.cxzflg,'C'    ; Did the user type a ^C? [25]
  495.     jne inpkt9
  496.     mov pack.state,'A'
  497.     ret
  498. inpkt9:    cmp flags.cxzflg,'E'    ; How about ^E?
  499.     jne inpk10        ; No just go on.
  500.     mov bx,offset cemsg    ; Null message for error packet.
  501.     call errpack
  502.     mov pack.state,'A'
  503.     ret
  504. inpk10:    mov bl,tmp        ; Get the original value. [20b]
  505.     cmp bl,flags.cxzflg    ; Did ^X/^Z flag change? [20b]
  506.     je inpk11        ; If not, just return failure.  [20b]
  507.     call intmsg         ; Else, say we saw the interrupt. [20b]
  508. inpk11:    jmp r
  509. INPKT    ENDP
  510.  
  511. inchr:    cmp flags.timflg,0    ; Are timeouts turned off.
  512.     je inchr1        ; Yes, so skip this stuff.
  513.     cmp trans.stime,0    ; Don't time out?
  514.     je inchr1        ; Yes, so skip this stuff.
  515.     mov loopct,0        ; Use to check for timeout.
  516.     mov ah,gettim        ; Get the time.
  517.     int dos
  518.     mov time,cx
  519.     mov time+2,dx
  520.     mov ah,0
  521.     mov al,trans.stime    ; Timeout when getting data.
  522.     mov cl,8
  523.     shl ax,cl        ; Move timeout to seconds field.
  524.     add time+2,ax        ; If get to this time, then timeout.
  525.     jnc inchr1
  526.     inc time
  527. inchr1:    call prtchr        ; Is there a character to read?
  528.      jmp inchr6        ; Got one.
  529.     mov dl,0FFH        ; To read in a char.
  530.     mov ah,dconio        ; Is a char on the console?
  531.     int dos
  532.     jz inchr2        ; If not go look for another char.
  533.     mov ah,al 
  534.     cmp ah,cr        ; Is it a carriage return?
  535.     je inchr5        ; If yes, then leave.
  536.     cmp ah,'Z'-100O        ; Control-Z? [20b]
  537.     je inchr4        ; Yes - flag it. [20b]
  538.     cmp ah,'X'-100O        ; Control-X? [20b]
  539.     je inchr4        ; Yes - flag it. [20b]
  540.     cmp ah,'E'-100O        ; Control-E?
  541.     je inchr4        ; Flag it and get rest of packet.
  542.     cmp ah,'C'-100O        ; Control-C? [25]
  543.     jne inchr2        ; No, then wait for input. [25]
  544.     add ah,100O        ; Make it printable. [25]
  545.     mov flags.cxzflg,ah    ; Save it. [25]
  546.     ret            ; Return right away. [25]
  547. inchr2:    cmp flags.timflg,0    ; Are timeouts turned off?
  548.     je inchr1        ; Yes, just check for more input.
  549.     cmp trans.stime,0    ; Doing time outs?
  550.     je inchr1        ; No, just go check for more input.
  551.     inc loopct
  552.     cmp loopct,maxlp    ; Times to go without checking time.
  553.     jne inchr1        ; Don't check yet.
  554.     mov ah,gettim        ; Get the current time.
  555.     int dos
  556.     mov ax,time
  557.     sub ax,cx        ; Check hours and minutes.
  558.     jl inchr5        ; Over the limit so fail.
  559.     jg inchr3        ; Under the limit, keep going.
  560.     mov ax,time+2
  561.     sub ax,dx        ; Else, check seconds and hundreds of seconds.
  562.     jle inchr5        ; Return failure.
  563. inchr3:    mov loopct,0        ; Reset counter.
  564.     jmp inchr1
  565. inchr4: add ah,100O        ; Make it printable. [20b]
  566.     mov flags.cxzflg,ah    ; Remember what we saw. [20b]
  567.     jmp inchr2        ; Continue getting input. [20b]
  568. inchr5:    ret
  569. inchr6: mov ah,al
  570.     mov bp,portval        ; Point to current port structure.
  571.     cmp ds:[bp].parflg,parnon    ; Is the parity none?    [10]
  572.     je inchr7        ; We're done.        [10]
  573.     and ah,7FH        ; Turn off the parity bit.
  574. inchr7:    cmp ds:[bp].floflg,0    ; Doing any flow control?
  575.     jne inchr8        ; Yes, check it out.
  576.     jmp rskp        ; No, just return the data.
  577. inchr8:    cmp xofsnt,true        ; Have we sent flow char (XOFF)?
  578.     je inchr9        ; Yes.
  579.     jmp rskp        ; No, just return.
  580. inchr9:    cmp count,mntrgl    ; Under the low trigger point?
  581.     jb inchra        ; Yes.
  582.     jmp rskp        ; No, just return.
  583. inchra:    push ax
  584.     mov bp,portval
  585.     mov ax,ds:[bp].flowc    ; Get flow control char (AH = XON, AL = XOFF).
  586.     call outchr        ; Send it (XON).
  587.     mov xofsnt,false    ; Turn off the flag.
  588.     pop ax
  589.     jmp rskp        ; Return the character.
  590.  
  591. ; Return next character in AL.
  592. GETCHR  PROC    NEAR
  593.     push bx
  594.     mov bx,pktptr        ; Get the packet pointer.
  595.     mov al,[bx]        ; Get the char.
  596.     inc bx
  597.     mov pktptr,bx
  598.     pop bx            ; Restore BX.
  599.     cmp al,trans.reol    ; Is it the EOL char?
  600.     jne getcr2        ; If not return retskp.
  601.     ret            ; If so return failure.
  602. getcr2: jmp rskp
  603. GETCHR  ENDP
  604.  
  605. ; Jumping to this location is like retskp.  It assumes the instruction
  606. ;   after the call is a jmp addr.
  607.  
  608. RSKP    PROC    NEAR
  609.     pop bp
  610.     add bp,3
  611.     push bp
  612.     ret
  613. RSKP    ENDP
  614.  
  615. ; Jumping here is the same as a ret.
  616.  
  617. R    PROC    NEAR
  618.     ret
  619. R    ENDP
  620.  
  621. code    ends
  622.     end
  623.